package org.pombo.gtb;

import java.util.ArrayList;
import java.util.List;

public abstract class Builder<T> {

	protected T entity;

	public Builder() {
		this.clear();
	}

	// TODO maybe this method can be implemented here. See:
	// http://docs.mockito.googlecode.com/hg/org/mockito/MockitoAnnotations.html
	public abstract void clear();

	public T build() {
		return this.entity;
	}

	public T buildAndClear() {
		T buildedEntity = this.build();
		this.clear();
		return buildedEntity;
	}

	public List<T> buildList(int size) {
		List<T> entities = new ArrayList<T>(size);
		for (int i = 0; i < size; i++) {
			entities.add(this.buildAndClear());
		}
		return entities;
	}
}
